home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / gnome-panel / migrate-fusa-config.py < prev   
Text File  |  2009-10-19  |  4KB  |  109 lines

  1. #!/usr/bin/python
  2.  
  3. import gconf
  4. import os.path
  5. import sys
  6.  
  7. from gettext import gettext as _
  8. import gettext
  9.  
  10. #FIXME: add checks here and run without UI if that fails to import
  11. import pygtk
  12. pygtk.require('2.0')
  13. import gtk
  14.  
  15. def error(primary, secondary):
  16.     d = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK)
  17.     d.set_markup("<b><big>%s</big></b>" % primary)
  18.     d.format_secondary_text(secondary)
  19.     d.run()
  20.     d.destroy()
  21.     
  22. def info(primary, secondary):
  23.     d = gtk.MessageDialog(type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK)
  24.     d.set_markup("<b><big>%s</big></b>" % primary)
  25.     d.format_secondary_text(secondary)
  26.     d.run()
  27.     d.destroy()
  28.  
  29. def associate_schemas_in_dir(client, engine, profile_dir, schema_dir):
  30.     """ 
  31.     helper that takes a gconf schema dir and creates a new profile dir
  32.     based on the schema, useful for e.g. adding a applet to the panel
  33.     """
  34.     for e in client.all_entries(schema_dir):
  35.         schema_key = os.path.basename(e.get_key())
  36.         key = os.path.join(profile_dir, schema_key)
  37.         engine.associate_schema(key, e.get_key())
  38.     client.suggest_sync()
  39.  
  40. if __name__ == "__main__":
  41.     gettext.bindtextdomain("gnome-panel")
  42.  
  43.     engine = gconf.engine_get_default()
  44.     client = gconf.client_get_for_engine(engine)
  45.     objects = client.all_dirs("/apps/panel/objects")
  46.  
  47.     logout=None
  48.     logout_panel=None
  49.     for d in objects:
  50.         if client.get_string(os.path.join(d,"action_type")) == "logout":
  51.             logout=os.path.basename(d)
  52.             logout_panel=client.get_string(os.path.join(d,"toplevel_id"))
  53.             break
  54.  
  55.     # we do not have a logout object or in a non-standard location, fail
  56.     if not logout:
  57.         error(_("No logout button found"),
  58.               _("The logout button can not be found or it is not in "
  59.                 "the standard location. Please update the panel "
  60.                 "configuration manually."))
  61.         sys.exit(1)
  62.  
  63.     if not os.path.exists("/usr/lib/fast-user-switch-applet/fast-user-switch-applet"):
  64.         error(_("No fast-user-switching applet found"),
  65.               _("The fusa applet can not be found or it is not in "
  66.                 "the standard location. Please update the panel "
  67.                 "configuration manually."))
  68.         sys.exit(1)
  69.  
  70.     # search for the fusa applet
  71.     applets = client.all_dirs("/apps/panel/applets")
  72.     for d in applets:
  73.         # move the fusa applet to new location
  74.         if (client.get_string(os.path.join(d,"bonobo_iid")) == "OAFIID:GNOME_FastUserSwitchApplet"):
  75.             client.set_int(os.path.join(d,"position"),0)
  76.             client.set_bool(os.path.join(d,"panel_right_stick"), True)
  77.             break
  78.     else:
  79.         # create a new one
  80.         applet_name = "applet_fusa_auto_migrated"
  81.         new_applet_name = os.path.join("/apps/panel/applets/",applet_name)
  82.         associate_schemas_in_dir(client, engine, new_applet_name,
  83.                                  "/schemas/apps/panel/objects")
  84.         client.set_string(os.path.join(new_applet_name, "bonobo_iid"), 
  85.                           "OAFIID:GNOME_FastUserSwitchApplet")
  86.         client.set_string(os.path.join(new_applet_name, "toplevel_id"), 
  87.                           logout_panel)
  88.         client.set_string(os.path.join(new_applet_name, "object_type"), 
  89.                           "bonobo-applet")
  90.         client.set_bool(os.path.join(new_applet_name, "panel_right_stick"), True)
  91.         l=client.get_list("/apps/panel/general/applet_id_list", gconf.VALUE_STRING)
  92.         l.append(applet_name)
  93.         client.set_list("/apps/panel/general/applet_id_list", gconf.VALUE_STRING, l)
  94.  
  95.     # remove the logout button (if its in the object_id_list)
  96.     l=client.get_list("/apps/panel/general/object_id_list", gconf.VALUE_STRING)
  97.     try:
  98.         l.remove(logout)
  99.         client.set_list("/apps/panel/general/object_id_list", gconf.VALUE_STRING, l)
  100.     except ValueError, e:
  101.         # print out message here so that it gets captured in .xsession-errors
  102.         sys.stderr.write("ignoring logout object '%s' (not in object_id_list: %s)" % (logout, e))
  103.  
  104.     # show nice information
  105.     info(_("Configuration updated"),
  106.          _("Your panel configuration is updated. Please logout "
  107.            "to complete the update."))
  108.  
  109.